/**
 * 打印共用js
 */
/***
 * 导出当前datagrid中的数据
 * @param grid
 */

function print(grid){
		var tableString = '<table cellspacing="0" class="pbn">';  
    		var frozenColumns = grid.datagrid("options").frozenColumns;  // 得到frozenColumns对象  
   		var columns = grid.datagrid("options").columns;    // 得到columns对象  
    		var nameList = new Array();  
  
    // 载入title  
    if (typeof columns != 'undefined' && columns != '') {  
        $(columns).each(function (index) {  
            tableString += '\n<tr>';  
            if (typeof frozenColumns != 'undefined' && typeof frozenColumns[index] != 'undefined') {  
                for (var i = 0; i < frozenColumns[index].length; ++i) {  
                    if (!frozenColumns[index][i].hidden) {  
                        tableString += '\n<th width="' + frozenColumns[index][i].width + '"';  
                        if (typeof frozenColumns[index][i].rowspan != 'undefined' && frozenColumns[index][i].rowspan > 1) {  
                            tableString += ' rowspan="' + frozenColumns[index][i].rowspan + '"';  
                        }  
                        if (typeof frozenColumns[index][i].colspan != 'undefined' && frozenColumns[index][i].colspan > 1) {  
                            tableString += ' colspan="' + frozenColumns[index][i].colspan + '"';  
                        }  
                        if (typeof frozenColumns[index][i].field != 'undefined' && frozenColumns[index][i].field != '') {  
                            nameList.push(frozenColumns[index][i]);  
                        }  
                        tableString += '>' + frozenColumns[0][i].title + '</th>';  
                    }  
                }  
            }  
            for (var i = 0; i < columns[index].length; ++i) {  
                if (!columns[index][i].hidden) {  
                    tableString += '\n<th width="' + columns[index][i].width + '"';  
                    if (typeof columns[index][i].rowspan != 'undefined' && columns[index][i].rowspan > 1) {  
                        tableString += ' rowspan="' + columns[index][i].rowspan + '"';  
                    }  
                    if (typeof columns[index][i].colspan != 'undefined' && columns[index][i].colspan > 1) {  
                        tableString += ' colspan="' + columns[index][i].colspan + '"';  
                    }  
                    if (typeof columns[index][i].field != 'undefined' && columns[index][i].field != '') {  
                        nameList.push(columns[index][i]);  
                    }  
                    tableString += '>' + columns[index][i].title + '</th>';  
                }  
            }  
            tableString += '\n</tr>';  
        });  
    }  
    // 载入内容  
    var rows = grid.datagrid("getRows"); // 这段代码是获取当前页的所有行  
    for (var i = 0; i < rows.length; ++i) {  
        tableString += '\n<tr>';  
        for (var j = 0; j < nameList.length; ++j) {  
            var e = nameList[j].field.lastIndexOf('_0');  
  
            tableString += '\n<td';  
            if (nameList[j].align != 'undefined' && nameList[j].align != '') {  
                tableString += ' style="text-align:' + nameList[j].align + ';"';  
            }  
            tableString += '>';  
            if (e + 2 == nameList[j].field.length) {  
                tableString += rows[i][nameList[j].field.substring(0, e)];  
            }  
            else  
                tableString += rows[i][nameList[j].field];  
            tableString += '</td>';  
        }  
        tableString += '\n</tr>';  
    }  
    tableString += '\n</table>'; 
    //$('#hlf').val(tableString);
    exportString=tableString;
    var url="print.jsp";
    var param2={
			doSize:false,
			shadow:false,
			content:'<iframe  scrolling="no" frameborder="0"  src="'+url+'" style="width:100%;height:95%;"></iframe>',
			title:'打印数据',
		    width:1000,    
		    height:800,
		    modal:true   	
	};
	mpgdialog1(param2);
} 


function mpgdialog1(param){	
		$('#dialog1').dialog(param);
		//$('#dialog1').window('center');
	}
